#pragma once
#include "Box2D/Box2D.h"
#include "cocos2d.h"
#include "GLES-Render.h"
#include "ConstDefine.h"
#include <vector>
#include <deque>
class PhysicalWorld;
class rayCastCallback:public b2RayCastCallback
{
public:
	PhysicalWorld *pParent;
	virtual float32 ReportFixture(    b2Fixture* fixture, const b2Vec2& point,const b2Vec2& normal, float32 fraction);
};
class PhysicalWorld:public b2ContactListener,
					public cocos2d::CCLayer
{
public:
	PhysicalWorld(void);
	~PhysicalWorld(void);

	
	virtual void raycastPlayerCollision()=0;
protected:
	
	bool  init();
	virtual void BeginContact(b2Contact* contact);
	virtual void EndContact(b2Contact* contact);
	virtual void PreSolve(b2Contact* contact, const b2Manifold* oldManifold);
	virtual void PostSolve(b2Contact* contact, const b2ContactImpulse* impulse);
	virtual void update(float tTime);
	virtual void draw();
	void	DestroyBody(b2Body *pbody);
	virtual void beginContact(cocos2d::CCNode *pNodeA,cocos2d::CCNode *pNodeB)=0;
	virtual void preSolveContact(cocos2d::CCNode *pNodeA,cocos2d::CCNode *pNodeB)=0;
	

	b2Body *CreatePlayerBody(float fR);
	b2Body *CreateLineBody(const b2Vec2 &vec1,const b2Vec2 &vec2);
	b2Body *CreateRectBody(b2Vec2 *pVec,int nVecNum);
	
	b2Body *CreateCircleBody(float fR);
	bool CreateRayCast(const std::list<b2Vec2> &allVec);
	
	
	
private:
	bool   CreateRayCast_V2V(b2Vec2 vec1,b2Vec2 vec2);
	bool initPhysicsWorld();
	b2World			*pWorld_;
	GLESDebugDraw	 debugView_;
	

};
